<?php
use Magento\Framework\App\Action\Action;
?>

<?php

$_productCollection = $block->getProductCollection();

$_helper = $this->helper('Magento\Catalog\Helper\Output');
?>
<?php if (!$_productCollection->count()): ?>
    <div class="message info empty"><div><?php /* @escapeNotVerified */ echo __('We can\'t find products matching the selection.') ?></div></div>
<?php else: ?>
    <?php echo $block->getToolbarHtml() ?>
    <?php echo $block->getAdditionalHtml() ?>
    <?php
    $viewMode = 'grid';
    $image = 'category_page_grid';
    $showDescription = false;
    $title = $block->getTitle() ? __($block->getTitle()) : '';
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::SHORT_VIEW;
    $classid = md5(json_encode($block->getData()));
    /**
     * Position for actions regarding image size changing in vde if needed
     */
    $pos = $block->getPositioned();
    ?>
    <div class="block widget block-products-list <?php /* @escapeNotVerified */ echo $viewMode; ?>">
        <?php if ($title):?>
            <div class="block-title">
                <span class="dot"> ●</span> <strong><?php /* @escapeNotVerified */ echo $title; ?></strong><span class="dot">●</span>
            </div>
        <?php endif ?>
        <div class="index_product block-content <?php echo $classid ?> owl-carousel owl-theme">
            <div  id="hotsale" class="products wrapper <?php /* @escapeNotVerified */ echo $viewMode; ?> product_list">
                <?php $iterator = 1; ?>
                <ol class="products list items product-items">
                    <?php /** @var $_product \Magento\Catalog\Model\Product */ ?>
                    <?php $j = 0;foreach ($_productCollection as $_product): ?>
                        <?php

                        if ($j >= 8) {
                            break;
                        }
                        ?>
                        <?php /* @escapeNotVerified */ echo($iterator++ == 1) ? '<li class="item product product-item">' : '</li><li class="item product product-item">' ?>
                        <div class="product-item-info" data-container="product-grid">
                            <?php
                            $productImage = $block->getImage($_product, $image);
                            if ($pos != null) {
                                $position = ' style="left:' . $productImage->getWidth() . 'px;'
                                    . 'top:' . $productImage->getHeight() . 'px;"';
                            }
                            ?>
                            <?php if($block->isShow('thumb')): ?>
                                <a href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>" class="product photo product-item-photo" tabindex="-1" title="<?php echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>">
                                    <?php echo $productImage->toHtml(); ?>
                                </a>
                            <?php endif ?>
                            <div class="product details product-item-details">
                                <?php
                                $_productNameStripped = $block->stripTags($_product->getName(), null, true);
                                ?>
                                <?php if($block->isShow('name')): ?>
                                    <strong class="product name product-item-name">
                                        <a class="product-item-link"
                                           href="<?php /* @escapeNotVerified */ echo $_product->getProductUrl() ?>">
                                            <?php /* @escapeNotVerified */ echo $_helper->productAttribute($_product, $_product->getName(), 'name'); ?>
                                        </a>
                                    </strong>
                                <?php endif ?>
                                <?php if($block->isShow('review')): ?>
                                    <?php if($block->getReviewsSummaryHtml($_product, $templateType)):?>
                                        <?php echo $block->getReviewsSummaryHtml($_product, $templateType); ?>
                                    <?php else:?>
                                        <div class="product-reviews-summary short">
                                            <div class="rating-summary">
                                                <span class="label"><span>Rating:</span></span>
                                                <div class="rating-result" title="0%">
                                                    <span style="width:0%"><span>0%</span></span>
                                                </div>
                                            </div>
                                            <div class="reviews-actions" style="display:inline-block">
                                                0&nbsp;<span>Reviews</span>
                                            </div>
                                        </div>
                                    <?php endif ?>
                                <?php endif ?>

                                <?php
                                $end = $this->helper('Mazentop\DiscountPrice\Helper\Data')->getProductDiscountEndDate($_product, $format = 'd F');
                                $today = time();
                                if($end && strtotime($end) > $today):
                                    $time = strtotime($end)-$today;
                                    ?>

                                    <div class="sepcialtime">
                                        <i class="fa fa-clock-o"></i>
                                        <span class="countdown" data-time="<?php echo $time?>"></span>
                                    </div>
                                <?php endif;?>

                                <?php if($block->isShow('price')): ?>
                                    <?php /* @escapeNotVerified */ echo $block->getProductPrice($_product);?>
                                <?php endif ?>
                                <div class="product-item-inner">
                                    <div class="product actions product-item-actions"<?php echo strpos($pos, $viewMode . '-actions') ? $position : ''; ?>>
                                        <?php if($block->isShow('addtocart')): ?>
                                            <div class="actions-primary"<?php echo strpos($pos, $viewMode . '-primary') ? $position : ''; ?>>
                                                <?php if ($_product->isSaleable()): ?>
                                                    <?php $postParams = $block->getAddToCartPostParams($_product); ?>
                                                    <form data-role="tocart-form" action="<?php /* @escapeNotVerified */ echo $postParams['action']; ?>" method="post">
                                                        <input type="hidden" name="product" value="<?php /* @escapeNotVerified */ echo $postParams['data']['product']; ?>">
                                                        <input type="hidden" name="<?php /* @escapeNotVerified */ echo Action::PARAM_NAME_URL_ENCODED; ?>" value="<?php /* @escapeNotVerified */ echo $postParams['data'][Action::PARAM_NAME_URL_ENCODED]; ?>">
                                                        <?php echo $block->getBlockHtml('formkey')?>
                                                        <button type="submit"
                                                                class="action tocart primary">
                                                            <i class="fa fa-shopping-cart"></i>
                                                            <span class="prompt"><?php /* @escapeNotVerified */ echo __('Add to Cart') ?></span>
                                                        </button>
                                                    </form>
                                                <?php else: ?>
                                                    <?php if ($_product->getIsSalable()): ?>
                                                        <div class="stock available"><span><?php /* @escapeNotVerified */ echo __('In stock') ?></span></div>
                                                    <?php else: ?>
                                                        <div class="stock unavailable"><span><?php /* @escapeNotVerified */ echo __('Out of stock') ?></span></div>
                                                    <?php endif; ?>
                                                <?php endif; ?>
                                            </div>
                                        <?php endif ?>
                                        <?php if($block->isShow('addto')): ?>
                                            <div data-role="add-to-links" class="actions-secondary"<?php echo strpos($pos, $viewMode . '-secondary') ? $position : ''; ?>>
                                                <?php
                                                $compareHelper = $this->helper('Magento\Catalog\Helper\Product\Compare');
                                                ?>
                                                <a href="#"
                                                   class="action"
                                                   aria-label="<?php echo $block->escapeHtml(__('Add to Compare')); ?>"
                                                   data-post='<?php /* @escapeNotVerified */ echo $compareHelper->getPostDataParams($_product); ?>'
                                                   role="button">
                                                    <i class="fa fa-signal"></i>
                                                    <span class="prompt"><?php /* @escapeNotVerified */ echo __('Compare') ?></span>
                                                </a>
                                                <?php if ($this->helper('Magento\Wishlist\Helper\Data')->isAllow()): ?>
                                                    <a href="#"
                                                       class="action wishlist"
                                                       aria-label="<?php echo $block->escapeHtml(__('Add to Wish List')); ?>"
                                                       data-post='<?php /* @escapeNotVerified */ echo $block->getAddToWishlistParams($_product); ?>'
                                                       data-action="add-to-wishlist"
                                                       role="button">
                                                        <i class="fa fa-heart-o"></i>
                                                        <span class="prompt"><?php /* @escapeNotVerified */ echo __('Wish List') ?></span>
                                                    </a>
                                                <?php endif; ?>

                                            </div>
                                        <?php endif ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <?php echo($iterator == count($_productCollection)+1) ? '</li>' : '' ?>
                        <?php $j++;endforeach; ?>
                </ol>
            </div>
            <?php echo $block->getToolbarHtml() ?>
            <?php if (!$block->isRedirectToCartEnabled()) : ?>
                <script type="text/x-magento-init">
				{
				    "[data-role=tocart-form], .form.map.checkout": {
				        "catalogAddToCart": {}
				    }
				}
				</script>
            <?php endif; ?>
        </div>
        <div class="more">
            <span>
                <a href="<?php echo $block->getUrl().str_replace('.','',str_replace(' ','-',trim(strtolower($title))))?>" title="<?php echo $title; ?>" title="<?php echo $title; ?>">
                    <?php echo __('More')?>
                    <i class="fa fa-angle-right"></i>
                </a>
            </span>
        </div>
    </div>
    <?php if($block->getData('show_slider')): ?>
        <script type="text/javascript">
            require(['jquery','Codazon_ProductFilter/owlcarousel/owl.carousel','domReady!'],function($){
                var owl = $('.index_product .product-items');
                if(owl.length){
                    owl.owlCarousel({
                        loop: false,
                        margin: 10,
                        responsiveClass: true,
                        nav: true,
                        dots: false,
                        responsive:{
                            0:{items: 	2},
                            320:{items:	2},
                            400:{items:	2, slideBy: 2},
                            768:{items:	2, slideBy: 2},
                            980:{items:	4, slideBy: 4},
                            1200:{items: 4, slideBy: 4}
                        }
                    });
                }
            });
        </script>
    <?php endif;endif; ?>

